package com.muyu.system.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.system.domain.DanmoMarketCollect;
import com.muyu.system.domain.DanmoMarketProducts;
import com.muyu.system.req.DanmoUserShopReq;
import com.muyu.system.service.IDanmoMarketCollectService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
import java.util.List;


/**
 * 书画市场收藏Controller
 *
 * @author yangle
 * @date 2024-09-12
 */
@Log4j2
@RestController
@RequestMapping("/collect")
public class DanmoMarketCollectController extends BaseController
{
    @Autowired
    private IDanmoMarketCollectService danmoMarketCollectService;

    @Autowired
    private HttpServletRequest httpServletRequest;
    /**
     * 查询书画市场收藏列表
     */
//    @RequiresPermissions("system:collect:list")
    @PostMapping("/list")
    public Result list(@RequestBody DanmoMarketCollect danmoMarketCollect)
    {
        Enumeration<String> headerNames = httpServletRequest.getHeaderNames();

        while (headerNames.hasMoreElements()) {
            String headerName = headerNames.nextElement();
            String headerValue = httpServletRequest.getHeader(headerName);
            // 记录每个请求头
            log.error("{}: {}", headerName, headerValue);
        }
        log.error(headerNames);
        PageHelper.startPage(danmoMarketCollect.getPageNum(),danmoMarketCollect.getPageSize());
        List<DanmoMarketProducts> list = danmoMarketCollectService.selectDanmoMarketCollectList(danmoMarketCollect);
        PageInfo<DanmoMarketProducts> danmoMarketCollectPageInfo = new PageInfo<>(list);
        if (danmoMarketCollectPageInfo.getList()==null){
            return Result.notLoggedIn("请登录");
        }
        return Result.success(danmoMarketCollectPageInfo);

    }

    /**
     * 导出书画市场收藏列表
     */
/*//    @RequiresPermissions("system:collect:export")
    @Log(title = "书画市场收藏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DanmoMarketCollect danmoMarketCollect)
    {
        List<DanmoMarketCollect> list = danmoMarketCollectService.selectDanmoMarketCollectList(danmoMarketCollect);
        ExcelUtil<DanmoMarketCollect> util = new ExcelUtil<DanmoMarketCollect>(DanmoMarketCollect.class);
        util.exportExcel(response, list, "书画市场收藏数据");
    }*/

    /**
     * 获取书画市场收藏详细信息
     */
//    @RequiresPermissions("system:collect:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id)
    {
        return success(danmoMarketCollectService.selectDanmoMarketCollectById(id));
    }

    /**
     * 新增书画市场收藏
     */
//    @RequiresPermissions("system:collect:add")
    @Log(title = "书画市场收藏", businessType = BusinessType.INSERT)
    @PostMapping("marketCollectAdd")
    public Result add(@RequestBody DanmoMarketCollect danmoMarketCollect)
    {
        return danmoMarketCollectService.insertDanmoMarketCollect(danmoMarketCollect);
    }

    /**
     * 修改书画市场收藏
     */
//    @RequiresPermissions("system:collect:edit")
    @Log(title = "书画市场收藏", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DanmoMarketCollect danmoMarketCollect)
    {
        return toAjax(danmoMarketCollectService.updateDanmoMarketCollect(danmoMarketCollect));
    }

    /**
     * 删除书画市场收藏
     */
//    @RequiresPermissions("system:collect:remove")
    @Log(title = "书画市场收藏", businessType = BusinessType.DELETE)
	@PostMapping("/del/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        return danmoMarketCollectService.deleteDanmoMarketCollectByIds(ids);
    }


    /**
     * 取消收藏
     */
    @PostMapping("/delCancelCollect")
    public Result delCancelCollect(@RequestBody DanmoUserShopReq danmoUserShopReq)
    {
        return danmoMarketCollectService.delCancelCollect(danmoUserShopReq);
    }
    /**
     * 查詢自己的收藏
     */
    @PostMapping("/myCollect")
    public Result<List<DanmoMarketCollect>> myCollect(@RequestBody DanmoMarketCollect danmoMarketCollect)
    {
        return danmoMarketCollectService.myCollect(danmoMarketCollect);
    }



}
